package com.wu.springboot_study.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wu.springboot_study.entity.User;
import com.wu.springboot_study.mapper.UserMapper;
import com.wu.springboot_study.service.IUserService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author benjamin_5
 * @Description
 * @date 2022/12/1
 */
@Service
@AllArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper,User> implements IUserService {

    private final UserMapper userMapper;

    @Override
    public List<User> list(String name, Integer age){
        return userMapper.list(name, age);
    }

    @Override
    public List<User> list2(String name, Integer age) {
        return this.list(Wrappers.<User>lambdaQuery().like(User::getName, name).eq(User::getAge, age));
    }

    @Override
    public User getUserByName(String name){
        return this.getOne(Wrappers.<User>lambdaQuery().eq(User::getName,name));
    }

    @Override
    public boolean isExistByName(String name){
        return this.count(Wrappers.<User>lambdaQuery().eq(User::getName, name).last("limit 1")) > 0;
    }


}
